import {
  pressures,
  createunifiedorder
} from '../../api/index.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    score: 0,//后台根据提交的压力测评计算出来的数值
    pressureId: 0,//推荐的压力课程ID
    tips: '',//压力课程的提示信息
    entity:{},//课程对象
    status:true,//课程状态
    gradientColor: {
      '0%': '#FFFFFF',
      '100%': '#9DC3FF'
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.pressureId && options.score && options.tips){
      this.setData({
        score: options.score,
        pressureId: options.pressureId,
        tips: options.tips
      })
    }
    let res = wx.getStorageSync('res')
    if (this.data.pressureId && this.data.pressureId!=-1){
      this.getPressures(this.data.pressureId)
    } else if (res.recommendedPressureId && !this.data.pressureId && res.recommendedPressureId!=-1){
      this.getPressures(res.recommendedPressureId)
      this.setData({
        score: res.pressureResult,
        pressureId: res.recommendedPressureId
      })
    }else{
      this.setData({
        status: false
      })
    }
  },

  //分享
  onShareAppMessage: function () {
    return {
      title: '我正在使用SMART睡眠训练计划，超有用！推荐给你',
      imageUrl: '../../images/98875.png'

    }
  },

  //推荐压力课程
  getPressures(id){
    pressures(id).then(res=>{
      console.log(res)
      this.setData({
        entity:res
      })
    })
  },

  //查看详情
  pressureDetail() {
    wx.navigateTo({
      url: "/pages/pressure-description/pressure-description?pressureId=" + this.data.pressureId,
    })
   
  },

  //获取更多计划
  getMorePlan(){
    wx.navigateTo({
      url: "/pages/more-course/more-course",
    })
   
  },

})